from django.db import models
from apps.common.base.models import BaseModel
from apps.merchant.cate.models import Cate
from apps.merchant.genera.models import Genera
from apps.merchant.activity.models import Activity
from apps.merchant.shop.models import Shop
from apps.merchant.tag.models import Tag

class Item(BaseModel):
    '''商品模型'''
    status = (
        (0, "关闭"),
        (1, "正常"),
    )
    checkStatus = (
        ('PASS', "审核通过"),
        ('CHECKING', "审核中"),
        ('REFUSE', "审核拒绝"),
    )
    genera = models.ForeignKey(Genera, related_name='genera_item', verbose_name='类目', on_delete=models.SET_NULL, null=True,
                             blank=True, db_constraint=False)
    shop = models.ForeignKey(Shop, related_name="shop_item", verbose_name='商户',
                               on_delete=models.SET_NULL, null=True, blank=True, db_constraint=False)
    cate = models.ForeignKey(Cate, related_name='cate_item', verbose_name='分类', on_delete=models.SET_NULL, null=True,
                             blank=True, db_constraint=False)
    activity = models.ForeignKey(Activity, related_name='activity_item', verbose_name='活动', on_delete=models.SET_NULL, null=True,
                             blank=True, db_constraint=False)
    tags = models.ManyToManyField(Tag, related_name='users_tag', blank=True, default=[], db_constraint=False)

    name = models.CharField("商品名称", max_length=200, blank=True, default='')
    shelfNum = models.CharField("货架号", max_length=200, blank=True, default='')
    coverPhotos = models.TextField("商品轮播图", max_length=10000, blank=True, default='')
    detailPhotosRichText = models.TextField("商品详情富文本", max_length=10000, blank=True, default='')
    sales = models.IntegerField("销量", default=0)
    stock = models.IntegerField("总库存", default=0)
    publicity = models.CharField("宣传语", max_length=200, blank=True, default='')
    intro = models.CharField("商品介绍", max_length=2000, blank=True, default='')
    status = models.IntegerField("上架/下架", choices=status, default=0)
    checkStatus = models.CharField("审核状态", max_length=200, choices=checkStatus, blank=True, default='PASS')
    keyword = models.CharField("关键字", max_length=200, blank=True, default='')
    isTransportFee = models.BooleanField("是否需要运费", blank=True, default=False)
    # isOnlinePay = models.BooleanField("是否线上支付", blank=True, default=False)
    payType = models.IntegerField("支付类型", blank=True, default=1)  # 1、线上支付 2、货到付款 3、价格面议
    transportFee = models.DecimalField("运费", max_digits=10, decimal_places=2, default=0)
    minShopCount = models.IntegerField("最小购买数量", default=1)
    maxShopCount = models.IntegerField("最大购买数量", default=0)
    isSingleSpec = models.IntegerField("是否单规格", blank=True, default=0)
    isCheckStock = models.IntegerField("是否校验库存", blank=True, default=1)
    incomes = models.DecimalField("抵扣所需积分", max_digits=10, decimal_places=2, default=0)
    expenseSendIncomesType = models.IntegerField("消费赠送积分方式", default=1)  # 1、比例 2、金额
    expenseSendIncomes = models.DecimalField("消费赠送积分", max_digits=10, decimal_places=2, default=0)
    directSendIncomesType = models.IntegerField("推荐奖励积分方式", default=1)  # 1、比例 2、金额
    directSendIncomes = models.DecimalField("推荐奖励积分", max_digits=10, decimal_places=2, default=0)

class Meta:
        verbose_name = 'Item'
        verbose_name_plural = verbose_name
